
#include "testStaticObject.h"

CPPUNIT_TEST_SUITE_REGISTRATION (testStaticObject);

void testStaticObject :: setUp (void){
}

void testStaticObject :: tearDown (void) {
}

void testStaticObject :: testLTrim (void)
{
	CPPUNIT_ASSERT_EQUAL (staticObject::ltrim(" test "), (string)"test ");
	CPPUNIT_ASSERT_EQUAL (staticObject::ltrim("\t test "), (string)"test ");
	CPPUNIT_ASSERT_EQUAL (staticObject::ltrim("\r test "), (string)"test ");
	CPPUNIT_ASSERT_EQUAL (staticObject::ltrim("\n test "), (string)"test ");
}

void testStaticObject :: testRTrim (void)
{
	CPPUNIT_ASSERT_EQUAL (staticObject::rtrim(" test "), (string)" test");
	CPPUNIT_ASSERT_EQUAL (staticObject::rtrim(" test \t"), (string)" test");
	CPPUNIT_ASSERT_EQUAL (staticObject::rtrim(" test \r"), (string)" test");
	CPPUNIT_ASSERT_EQUAL (staticObject::rtrim(" test \n"), (string)" test");
}

void testStaticObject :: testTrim (void)
{
	CPPUNIT_ASSERT_EQUAL (staticObject::trim(" test "), (string)"test");
	CPPUNIT_ASSERT_EQUAL (staticObject::trim("\t test \t"), (string)"test");
	CPPUNIT_ASSERT_EQUAL (staticObject::trim("\r test \r"), (string)"test");
	CPPUNIT_ASSERT_EQUAL (staticObject::trim("\n test \n"), (string)"test");
}

void testStaticObject :: testCharToLower (void) {
	CPPUNIT_ASSERT_EQUAL (staticObject::charToLower('a'), 'a');
	CPPUNIT_ASSERT_EQUAL (staticObject::charToLower('A'), 'a');
	CPPUNIT_ASSERT_EQUAL (staticObject::charToLower('Z'), 'z');
	CPPUNIT_ASSERT_EQUAL (staticObject::charToLower('z'), 'z');
	CPPUNIT_ASSERT_EQUAL (staticObject::charToLower('!'), '!');
	CPPUNIT_ASSERT_EQUAL (staticObject::charToLower('<'), '<');
	CPPUNIT_ASSERT_EQUAL (staticObject::charToLower('}'), '}');
}
void testStaticObject :: testCharToUpper (void) {
	CPPUNIT_ASSERT_EQUAL (staticObject::charToUpper('A'), 'A');
	CPPUNIT_ASSERT_EQUAL (staticObject::charToUpper('a'), 'A');
	CPPUNIT_ASSERT_EQUAL (staticObject::charToUpper('z'), 'Z');
	CPPUNIT_ASSERT_EQUAL (staticObject::charToUpper('Z'), 'Z');
	CPPUNIT_ASSERT_EQUAL (staticObject::charToUpper('!'), '!');
	CPPUNIT_ASSERT_EQUAL (staticObject::charToUpper('<'), '<');
	CPPUNIT_ASSERT_EQUAL (staticObject::charToUpper('}'), '}');
}


void testStaticObject :: testStringToLower (void) {
	CPPUNIT_ASSERT_EQUAL (
		staticObject::stringToLower(
			"Hier ein String <>"
		),
		(string)"hier ein string <>"
	);
	CPPUNIT_ASSERT_EQUAL (
		staticObject::stringToLower(
			"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
		),
		(string)"abcdefghijklmnopqrstuvwxyz"
	);
	CPPUNIT_ASSERT_EQUAL (
		staticObject::stringToLower(
			"\t!§$%&/()=?\n"
		),
		(string)"\t!§$%&/()=?\n"
	);
}

void testStaticObject :: testStringToUpper (void) {
	CPPUNIT_ASSERT_EQUAL (
		staticObject::stringToUpper(
			"Hier ein String <>"
		),
		(string)"HIER EIN STRING <>"
	);
	CPPUNIT_ASSERT_EQUAL (
		staticObject::stringToUpper(
			"abcdefghijklmnopqrstuvwxyz"
		),
		(string)"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	);
	CPPUNIT_ASSERT_EQUAL (
		staticObject::stringToUpper(
			"\t!§$%&/()=?\n"
		),
		(string)"\t!§$%&/()=?\n"
	);
}

void testStaticObject :: testExplode (void) {
	map<string,string> newMap = staticObject::explode(",", "test1=value1,test2=value2,test3=value3,test4=value4");
	CPPUNIT_ASSERT_EQUAL (newMap["test1"] , (string)"value1");
	CPPUNIT_ASSERT_EQUAL (newMap["test2"] , (string)"value2");
	CPPUNIT_ASSERT_EQUAL (newMap["test3"] , (string)"value3");
	CPPUNIT_ASSERT_EQUAL (newMap["test4"] , (string)"value4");
}

void testStaticObject :: testImplode (void) {
	map<string,string> newMap;
	newMap["test1"] ="value1";
	newMap["test2"] ="value2";
	newMap["test3"] ="value3";
	newMap["test4"] ="value4";
	CPPUNIT_ASSERT_EQUAL (
		(string)"test1=value1,test2=value2,test3=value3,test4=value4",
		staticObject::implode(",",newMap)
	);
}

void testStaticObject :: testStringReplace(void) {
	CPPUNIT_ASSERT_EQUAL (
		(string)"testStringReplaceTheWord",
		staticObject::stringReplace("To","","testStringToReplaceTheToWord")
	);

}

void testStaticObject :: testStringReplaceWithSpecialChars(void) {
	CPPUNIT_ASSERT_EQUAL (
		(string)"testStringReplace",
		staticObject::stringReplace("$","","test$String$Replace")
	);
}

void testStaticObject :: testSearchInContentFor(void) {
	string *content = new string("firstcontent1next");
	CPPUNIT_ASSERT_EQUAL (
		(string)"content1",
		staticObject::searchInContentFor(content,"first","next")
	);
	delete content;
}

void testStaticObject :: testSearchInContentForWithfirstPos(void) {
	string *content = new string("firstcontent1nextPOSfirstcontent2next");
	CPPUNIT_ASSERT_EQUAL (
		(string)"content2",
		staticObject::searchInContentFor(content,"first","next","POS")
	);
	delete content;
}

void testStaticObject :: testGetTimeStamp(void) {
	CPPUNIT_ASSERT_EQUAL (
		(string)"1230764400",
		staticObject::timestamp("2009-01-01")
	);
	CPPUNIT_ASSERT_EQUAL (
		(string)"1234567890",
		staticObject::timestamp("2009-02-14 00:31:30")
	);
	CPPUNIT_ASSERT_EQUAL (
		(string)"82800",
		staticObject::timestamp("1970-01-02")
	);
}

void testStaticObject :: testMakeTimeStruct(void) {
	tm tmStruct = staticObject::makeTimeStruct("1970-01-01","");
	CPPUNIT_ASSERT_EQUAL (
		1970,
		tmStruct.tm_year + 1900
	);
	CPPUNIT_ASSERT_EQUAL (
		1,
		tmStruct.tm_mon + 1
	);
}


